import React from 'react';
import { Route, Redirect } from 'dva/router';
import Authority from './Authority';

class Permissions extends React.Component {
  render() {
    const { component: Component, authority, redirectPath, render, ...rest } = this.props;
    return (
      <Authority
        authority={authority}
        noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />}
      >
        <Route {...rest} render={props => (Component ? <Component {...props} /> : render(props))} />
      </Authority>
    );
  }
}

export default Permissions;
